package 特别数的和;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int res = 0;
        for (int i = 1; i <= n; i++) {
            int x = i;
            while (x > 0) {
                int t = x % 10;
                if (t == 1 || t == 2 || t == 9 || t == 0) {
                    res += i;
                    break;
                }
                x /= 10;
            }
        }
        System.out.println(res);
    }
}
